package com.yuncheng.oaApi.FlowController;


import com.yuncheng.entity.YcSysUser;
import com.yuncheng.oaApi.constant.NkConstant;
import com.yuncheng.oaApi.vo.NkRsHtspjlVo;
import com.yuncheng.oaApi.vo.OaFlowVo;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.Result;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.oaApi.FlowService.NewNkRsHtspjlFlowService;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.oaApi.busService.MyLcFlowService;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.mapper.NkRsHtspjlFlowMapper;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.*;
import groovy.lang.Lazy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import utils.DateConversionUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

@Api(tags = "NEW_NK-合同支付申请接口")
@RestController
@RequestMapping("/api/spzx-oa/nk-htzfsq")
public class NewNkRsHtspjlFlowController {
    private static final Logger log = LoggerFactory.getLogger(NewNkRsHtspjlFlowController.class);


    @Resource
    private IOaSpcySqsxJobService spcySqsxJobService;

    @Resource
    private IOaYcSysUserService ycSysUserService;

    @Resource
    @Lazy
    private IOaSysTzMessageService sysTzMessageService;

    @Resource
    @Lazy
    private MyLcFlowService myLcFlowService;

    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;

    @Resource
    @Lazy
    private NkRsHtspjlFlowMapper nkRsHtspjlFlowMapper;

    @Resource
    @Lazy
    private NewNkRsHtspjlFlowService newNkRsHtspjlFlowService;

    @Resource
    @Lazy
    private INkRsHtspjlService nkRsHtspjlService;

    @Resource
    @Lazy
    private INkRsHtglService nkRsHtglService;

    @Resource
    @Lazy
    private INkRsXmyszbbService nkRsXmyszbbService;


    @Resource
    @Lazy
    private INkHtHtbgglService nkHtbgglService;

    @Resource
    @Lazy
    private IOaXzswspEntityService oaXZswspEntityService;



    /**
     * 合同列表
     */
    @AutoLog(value = "合同列表-分页列表查询")
    @ApiOperation(value = "合同列表-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(NkRsHtspjl nkRsHtspjl, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<NkRsHtspjl> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFhtbh()), NkRsHtspjl::getFhtbh, nkRsHtspjl.getFhtbh());
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFhtmc()), NkRsHtspjl::getFhtmc, nkRsHtspjl.getFhtmc());
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFhtje()), NkRsHtspjl::getFhtje, nkRsHtspjl.getFhtje());
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFcgfs()), NkRsHtspjl::getFcgfs, nkRsHtspjl.getFcgfs());
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFzbgysmc()), NkRsHtspjl::getFzbgysmc, nkRsHtspjl.getFzbgysmc());
        queryWrapper.like(StringUtils.isNotBlank(nkRsHtspjl.getFhtzt()), NkRsHtspjl::getFhtzt, nkRsHtspjl.getFhtzt());

        Page<NkRsHtspjl> page = new Page<>(pageNo, pageSize);
        IPage<NkRsHtspjl> pageList = nkRsHtspjlService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }

    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程监控-分页查询")
    @ApiOperation(value = "流程监控-分页查询")
    @GetMapping("flowJkPage")
    public HttpResult flowJkPage(
            NkRsHtspjlVo nkRsHtspjlVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        nkRsHtspjlVo.setFlcmc(OaFlowConstant.NK_HTZFLC_NAME);
        Page<NkRsHtspjlVo> page = new Page<>(pageNo, pageSize);

        IPage<NkRsHtspjlVo> list = null;
        if (StringUtils.isNotBlank(nkRsHtspjlVo.getOaid())){
            NkRsHtspjl xzswsp = nkRsHtspjlService.getById(nkRsHtspjlVo.getOaid());
            if (xzswsp != null){
                list = nkRsHtspjlFlowMapper.flowJkPage(page,onlyCurrentUser,user,nkRsHtspjlVo);
            }
        }

        return HttpResult.ok(list);
    }

    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程列表-分页查询")
    @ApiOperation(value = "流程列表-分页查询")
    @GetMapping("flowJobPage")
    public HttpResult<?> flowJobPage(
            NkRsHtspjlVo nkRsHtspjlVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        nkRsHtspjlVo.setFlcmc(OaFlowConstant.NK_HTZFLC_NAME);
        if (StringUtils.isBlank(nkRsHtspjlVo.getFblzt())) {
            nkRsHtspjlVo.setFblzt(OaCommonFlowConstant.BLZT_DB);
        }
        Page<NkRsHtspjlVo> page = new Page<>(pageNo, pageSize);
        IPage<NkRsHtspjlVo> list = nkRsHtspjlFlowMapper.flowJobPage(page, onlyCurrentUser, user, nkRsHtspjlVo);
        return HttpResult.ok(list);
    }


    /**
     * 我的已办
     */
    @AutoLog(value = "流程列表-我的已办")
    @ApiOperation(value = "流程列表-我的已办")
    @GetMapping("myJobPage")
    public HttpResult<?> myJobPage(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            NkRsHtspjlVo nkRsHtspjlVo) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        Page<NkRsHtspjlVo> page = new Page<>(pageNo, pageSize);
        IPage<NkRsHtspjlVo> list = nkRsHtspjlFlowMapper.myYbFlowPage(page, true, user, nkRsHtspjlVo);
        return HttpResult.ok(list);
    }


    /**
     * 数据修订
     */
    @AutoLog(value = "列表-数据修订")
    @ApiOperation(value = "列表-数据修订")
    @GetMapping("Pagesjxd")
    public HttpResult<?> Pagesjxd(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            NkRsHtspjlVo nkRsHtspjlVo) {

        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }

        Page<NkRsHtspjlVo> page = new Page<>(pageNo, pageSize);
        IPage<NkRsHtspjlVo> list = nkRsHtspjlFlowMapper.myYbFlowPage(page, false, user, nkRsHtspjlVo);
        return HttpResult.ok(list);
    }


    @AutoLog(value = "根据合同id查询登记的合同")
    @ApiOperation(value = "列表-根据合同id查询登记的合同")
    @GetMapping("selectHtByHtid")
   public HttpResult<?> selectHtByHtid(String htid){
        List<NkRsHtgl> list = new ArrayList();
        if (StringUtils.isNotBlank(htid)){
            list = nkRsHtglService.list(new LambdaQueryWrapper<NkRsHtgl>().eq(NkRsHtgl::getId, htid));
        }
        return HttpResult.ok(list);
   }

    @AutoLog(value = "根据项目预算指标id查询项目预算指标")
    @ApiOperation(value = "列表-根据项目预算指标id查询项目预算指标")
    @GetMapping("selectxmysBysid")
    public HttpResult<?> selectxmysBysid(String fxmyszbid){
        List<NkRsXmyszbb> list = new ArrayList();
        if (StringUtils.isNotBlank(fxmyszbid)){
            list = nkRsXmyszbbService.list(new LambdaQueryWrapper<NkRsXmyszbb>().eq(NkRsXmyszbb::getId, fxmyszbid));
        }
        return HttpResult.ok(list);
    }

    @AutoLog(value = "发起合同审批申请")
    @ApiOperation(value = "发起合同审批申请")
    @PostMapping(value = "initBzFlow")
    public HttpResult<?> initBzFlow(@RequestBody NkRsHtspjl nkRsHtspjl) {

        String oaid = "";
        //当前人的id
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser == null) {
            return HttpResult.error("当前登录已失效，请重新登录");
        }
        if (StringUtils.isNotBlank(nkRsHtspjl.getId())){
            NkRsHtspjl nkids = nkRsHtspjlService.getById(nkRsHtspjl.getId());

            ConvertUtils.register(new DateConvert(), Date.class);
            try {
                BeanUtils.populate(nkids, BeanUtils.describe(nkRsHtspjl));
            } catch (IllegalAccessException e) {
                log.error("出错-保存事项【非法访问异常】,{}", e.getMessage());
            } catch (InvocationTargetException e) {
                log.error("出错-保存事项【调用TargetException】,{}", e.getMessage());
            } catch (NoSuchMethodException e) {
                log.error("出错-找不到可用方法", e.getMessage());
            }
            oaid = nkRsHtspjl.getId();

            nkids.setFtxr(currentUser.getName());
            nkids.setFtxrid(currentUser.getId());
            nkids.setFtxrks(currentUser.getOrgName());
            nkids.setFtxrksid(currentUser.getOrgId());
            nkids.setFtxsj(DateConversionUtils.DateToDays(new Date()));

            nkRsHtspjlService.updateById(nkids);
        }else {
            oaid = GetUuIdUtils.ReplaceUuId();
            nkRsHtspjl.setId(oaid);

            nkRsHtspjl.setFtxr(currentUser.getName());
            nkRsHtspjl.setFtxrid(currentUser.getId());
            nkRsHtspjl.setFtxrks(currentUser.getOrgName());
            nkRsHtspjl.setFtxrksid(currentUser.getOrgId());
            nkRsHtspjl.setFtxsj(DateConversionUtils.DateToDays(new Date()));


            if (StringUtils.isNotBlank(nkRsHtspjl.getFcgpm()) && StringUtils.isBlank(nkRsHtspjl.getFhtbh())){
                String fhtbh = nkHtbgglService.getFhtbh(nkRsHtspjl.getFcgpm());
                nkRsHtspjl.setFhtbh(fhtbh);
            }



            nkRsHtspjlService.save(nkRsHtspjl);
        }

        String msg = "保存成功";
        String lcmbCode = OaFlowConstant.NK_HTSPLC;

        OaJobEntity job = new OaJobEntity();
        // 初始化流程
        Result result = newNkRsHtspjlFlowService.createProcess(lcmbCode,oaid, currentUser);
        //做一次规则校验 如果查到此oaid 在表中已经插入 那就执行更新
        NkRsHtspjl nkRsHtspjl1 = nkRsHtspjlService.getById(oaid);
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        String bt = currentUser.getName()+"提交的合同支付申请"; //标题
        String zy = "合同名称:["+nkRsHtspjl1.getFhtmc() +"]"+"\n"
                +"合同金额:["+ nkRsHtspjl1.getFhtje() + "]"+"\n"
                +"采购方式:["+ nkRsHtspjl1.getFcgfs() + "]"+"\n"
                +"中标供应商名称:["+ nkRsHtspjl1.getFzbgysmc() + "]"+"\n";
        if (oaProcessBusinessList.size() == 0){
            //初始化的时候 像 流程业务主表添加拼接初始化数据
            oaProcessBusinessService.addProcess(oaid,zy,bt,lcmbCode,OaFlowConstant.NK);

        }else {
            String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
            OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
            oaProcessBusiness.setFzy(zy);
            oaProcessBusinessService.updateById(oaProcessBusiness);

        }

        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }else {
            job = (OaJobEntity)result.getResult();
            if (job != null) {
                // 是否提交流程
                if(StringUtils.isBlank(oaid)){
                    return HttpResult.error("参数丢失");
                }
                String nextNodeId = "";
                String nextNodeDbrId = "";
                if (StringUtils.isNotBlank(nkRsHtspjl.getFsffqlc()) && nkRsHtspjl.getFsffqlc().equals(OaCommonFlowConstant.SFFQLC_YES)) {
                    YcSysUser ycSysUser =  ycSysUserService.getById(currentUser.getId());
                    if (StringUtils.isBlank(nkRsHtspjl.getFlczt())) {
                        nkRsHtspjl.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
                    }

                    Result result1 = newNkRsHtspjlFlowService.passJob(oaid,job.getId(),"同意", nextNodeId, nextNodeDbrId);

                    if (!result1.isSuccess()) {
                        return HttpResult.error(result.getMessage());
                    }
                    msg = "提交成功";
                    //提交完成后 更新通知信息
                    sysTzMessageService.tjMessage(oaid);

                    List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                            .eq(OaProcessBusiness::getFpid, oaid));
                    OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
                    OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
                    byId1.setFsfkch(0);
                    byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
                    oaProcessBusinessService.updateById(byId1);

                    myLcFlowService.recall(oaid);
                }
            }
        }

        HashMap map = new HashMap();
        map.put("msg",msg);
        map.put("nkMap",nkRsHtspjl);
        map.put("jobMap",job);

        return HttpResult.ok(map);
    }

    /**
     * 内控-合同支付申请保存接口
     */
    @AutoLog(value = "内控-合同支付申请保存接口")
    @ApiOperation(value = "内控-合同支付申请保存接口")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody OaFlowVo oaFlowVo) {
        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SAVE; // 保存

        String jobId = oaFlowVo.getJobid(); // 当前流程任务id
        String oaid = oaFlowVo.getOaid(); // 当前办公主键id
        String opinion = oaFlowVo.getOpinion(); // 办理意见

        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.OA_LGQS);
        }
        if (StringUtils.isBlank(jobId)){
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        // 流程处理
        Result httpResult = newNkRsHtspjlFlowService.handleFlow(oaFlowVo, null, jobId, oaid, submitType, opinion);
        if (!httpResult.isSuccess()){
            return HttpResult.error(httpResult.getMessage());
        }
        Map map = new HashMap();
        HttpResult<Object> res = new HttpResult<>(true);
        res.setMessage("保存成功");
        res.setResult(map);
        return res;
    }


    @AutoLog(value = "内控-合同支付申请提交接口")
    @ApiOperation(value = "内控-合同支付申请提交接口")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody OaFlowVo oaFlowVo) {
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交

        String jobId = oaFlowVo.getJobid();
        String oaid = oaFlowVo.getOaid();
        String opinion = oaFlowVo.getOpinion();
        NkRsHtspjl nkRsHtspjl = nkRsHtspjlService.getById(oaid);
        OaJobEntity jobid = spcySqsxJobService.getById(jobId);
        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.NK_YSTPSQ);
        }
        HashMap<String, Object> map = oaFlowVo.getMap();
        String o = (String) map.get("fcgpm");
        if (StringUtils.isBlank(o) && StringUtils.isBlank(nkRsHtspjl.getFcgpm())){
            throw new BusinessException("采购项目为空，请选择采购项目");
        }
        if (StringUtils.isBlank(nkRsHtspjl.getFhtbh())){
            String fhtbh = nkHtbgglService.getFhtbh(o);
            nkRsHtspjl.setFhtbh(fhtbh);
        }

        if (jobid.getFhjmc().equals(OaFlowConstant.HTSPT_HJMC_ZXZR)) {

        } else {
            nkRsHtspjl.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        }
        if (StringUtils.isBlank(nkRsHtspjl.getFsffqlc())) {
            nkRsHtspjl.setFsffqlc(OaCommonFlowConstant.SFFQLC_YES);
        }

        nkRsHtspjlService.updateById(nkRsHtspjl);

        if (StringUtils.isBlank(jobId)) {
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        /* if (StringUtils.isBlank(opinion)){
            return HttpResult.error("请填写办理意见");2
        }*/
        OaJobEntity nowJob = null;
        Result httpResult1 = newNkRsHtspjlFlowService.handleFlow(oaFlowVo, nowJob, jobId, oaid, submitType, opinion);
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }
        List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
        OaProcessBusiness oaProcessBusiness1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
        oaProcessBusiness1.setFdjh(nkRsHtspjl.getFhtbh());
        oaProcessBusiness1.setFsfkch(0);
        oaProcessBusiness1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);


        //提交时在更新一次摘要数据
        String lcmbCode = OaFlowConstant.NK_HTSPLC;
        NkRsHtspjl nkRsHtspjl1 = nkRsHtspjlService.getById(oaid);
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        String bt = currentUser.getName()+"提交的合同支付申请"; //标题
        String zy = "合同名称:["+nkRsHtspjl1.getFhtmc() +"]"+"\n"
                +"合同金额:["+ nkRsHtspjl1.getFhtje() + "]"+"\n"
                +"采购方式:["+ nkRsHtspjl1.getFcgfs() + "]"+"\n"
                +"中标供应商名称:["+ nkRsHtspjl1.getFzbgysmc() + "]"+"\n";
        if (oaProcessBusinessList.size() == 0){
            //初始化的时候 像 流程业务主表添加拼接初始化数据
            oaProcessBusinessService.addProcess(oaid,zy,bt,lcmbCode,OaFlowConstant.NK);

        }else {

            oaProcessBusiness1.setFzy(zy);
            oaProcessBusinessService.updateById(oaProcessBusiness1);

        }

        oaProcessBusinessService.updateById(oaProcessBusiness1);
        //提交完成后 更新待办信息
        sysTzMessageService.tjMessage(oaid);
        myLcFlowService.recall(oaid);


        return HttpResult.ok("提交成功");
    }





    /**
     * 批量查询
     */
    @AutoLog(value = "批量查询")
    @ApiOperation(value = "批量查询")
    @ApiImplicitParam(value = "jobids", name = "jobids", required = true)
    @GetMapping(value = "queryBatchJobByJobIds")
    public HttpResult<?> queryBatchJobByJobIds(@RequestParam("jobids")String jobids) {
        if (StringUtils.isBlank(jobids)) {
            return HttpResult.error("参数不能为空,请选择数据");
        }
        List<Map> mapList = new ArrayList<>();
        List<String> jobidsList = Arrays.asList(jobids.split(","));
        if (CollectionUtils.isNotEmpty(jobidsList)) {
            for (String jobid : jobidsList){
                mapList.add(newNkRsHtspjlFlowService.getJobConcernByJobId(jobid));
            }
        }
        return HttpResult.ok(mapList);
    }

    /**
     * 查询当前流程任务详情-通过当前流程任务id
     */
    @AutoLog(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiOperation(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiImplicitParam(value = "jobid", name = "流程任务id", required = true)
    @GetMapping(value = "queryJobByJobId")
    public HttpResult<?> queryJobByJobId(@RequestParam("jobid") String jobid) {
        if (StringUtils.isBlank(jobid)) {
            return HttpResult.error("流程任务id不能为空");
        }
        Map map = newNkRsHtspjlFlowService.getJobConcernByJobId(jobid);
        return HttpResult.ok(map);
    }

    /**
     * 获取已办列表-通过当前流程id-自定义退回
     *
     * @param jobid
     * @return
     */
    @AutoLog(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiOperation(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid", value = "流程任务id"),
            @ApiImplicitParam(name = "isZdhj", value = "是否指定环节，默认：true，指定")
    })
    @GetMapping(value = "queryAllYbJob")
    public HttpResult<?> queryAllYbJob(@RequestParam(value = "jobid", defaultValue = "") String jobid,
                                       @RequestParam(value = "isZdhj", defaultValue = "true") boolean isZdhj) {
        List<Map<String, String>> currentJobPrevious = newNkRsHtspjlFlowService.getCurrentJobPrevious(jobid, isZdhj);
        return HttpResult.ok(currentJobPrevious);
    }

    /**
     * 退回环节
     *
     * @return
     */
    @AutoLog(value = "自定义-退回环节")
    @ApiOperation(value = "自定义-退回环节")
    @PostMapping(value = "returnUpperzdyFlowJob")
    public HttpResult<?> returnUpperzdyFlowJob(@RequestBody OaReturnVo oaReturnVo) {
        newNkRsHtspjlFlowService.returnZdJob(oaReturnVo);

        //退回更新通知信息
        OaJobEntity oaJobEntity = spcySqsxJobService.getById(oaReturnVo.getJobid());
        String fpid = oaJobEntity.getFpid();
        sysTzMessageService.endMessage(fpid,false,false,true);

        return HttpResult.ok("退回成功");
    }


    /**
     * 查看可以绑定行政事务的列表
     */
    @AutoLog(value = "查看可以绑定行政事务的列表")
    @ApiOperation(value = "查看可以绑定行政事务的列表")
    @GetMapping(value = "selectXzswList")
    public HttpResult<?> selectXzswList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<OaXzswspEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OaXzswspEntity::getFlczt,OaCommonFlowConstant.FLOW_LCJS);
        queryWrapper.eq(OaXzswspEntity::getFlb,OaFlowConstant.XZSWLB_CW);
        queryWrapper.eq(OaXzswspEntity::getFbxzt,NkConstant.BXZT_WBX);


        Page<OaXzswspEntity> page = new Page<>(pageNo, pageSize);
        IPage<OaXzswspEntity> pageList = oaXZswspEntityService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }




    /**
     * 绑定行政事务
     */
    @AutoLog(value = "绑定行政事务")
    @ApiOperation(value = "绑定行政事务")
    @GetMapping(value = "bdXzsw")
    public HttpResult<?> bdXzsw(String htid,String xzswid,String xzswmc) {

        NkRsHtspjl nkRsHtspjl  = nkRsHtspjlService.getById(htid);
        if (StringUtils.isNotBlank(nkRsHtspjl.getFxzswid())){
            nkRsHtspjl.setFxzswid(xzswid);
        }
        nkRsHtspjl.setFxzswmc(xzswmc);
        nkRsHtspjlService.updateById(nkRsHtspjl);

        //更新行政事务的合同绑定状态
        OaXzswspEntity xzswspEntity = oaXZswspEntityService.getById(xzswid);
        xzswspEntity.setFhtbdzt(OaCommonFlowConstant.YES);
        xzswspEntity.setFbxzt(NkConstant.BXZT_YBX);
        oaXZswspEntityService.updateById(xzswspEntity);

        return HttpResult.ok("成功");

    }


    /**
     * 删除绑定事务
     */
    @AutoLog(value = "删除绑定事务")
    @ApiOperation(value = "删除绑定事务")
    @GetMapping(value = "scbdXzsw")
    public HttpResult<?> scbdXzsw(String htid,String xzswid) {

        NkRsHtspjl nkRsHtspjl  = nkRsHtspjlService.getById(htid);
        nkRsHtspjl.setFxzswid("");
        nkRsHtspjl.setFxzswmc("");

        nkRsHtspjlService.updateById(nkRsHtspjl);

        //更新行政事务的合同绑定状态
        OaXzswspEntity xzswspEntity = oaXZswspEntityService.getById(xzswid);
        xzswspEntity.setFhtbdzt(OaCommonFlowConstant.NO);
        xzswspEntity.setFbxzt(NkConstant.BXZT_WBX);
        oaXZswspEntityService.updateById(xzswspEntity);

        return HttpResult.ok("成功");

    }

    /**
     * 删除
     */
    @AutoLog(value = "删除")
    @ApiOperation(value = "删除")
    @GetMapping(value = "delete")
    public HttpResult<?> delete(@RequestParam(name = "id", required = true) String id) {
        nkRsHtspjlService.removeById(id);
        return HttpResult.ok("删除成功!");
    }









}
